package com.icehand.echarts.model;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhoujunmei
 * @date 2019-08-02
 */
public class EchartsOptionBuilder {
    public static EchartsOption build(String title, List<String> legend, List<String> dimensions, List<List<Double>> allData,
                                      String unit){
        List<Series> seriesList = new ArrayList<>();
        for(int i=0;i<allData.size();i++){
            seriesList.add(new Series().setData(allData.get(i))
                    .setName(legend.get(i))
                    .setType("bar")
                    .setLabel(new Label().setNormal(new Normal().setShow(true).setTextBorderWidth(2)))
            );
        }
        return new EchartsOption()
                .setTitle(new Title().setText(title))
                .setTooltip(new Tooltip().setTrigger("axis")
                        .setAxisPointer(new AxisPointer().setType("shadow")))
                .setLegend(new Legend().setData(legend))
                .setGrid(new Grid().setLeft("100"))
                .setToolbox(new Toolbox()
                        .setShow(false)
                        .setFeature(new Feature()
                                .setSaveAsImage(new SaveAsImage().setType("png"))))
                .setXAxis(new XAxis().setType("value").setName(unit))
                .setYAxis(new YAxis().setType("category").setInverse(false).setData(dimensions).setAxisLabel(new AxisLabel().setMargin(20)))
                .setSeries(seriesList);
    }
}
